package logic

import (
	"clinic-go/models/mysql"
	"context"
	"errors"

	"clinic-go/clinicrpc/clinicrpc"
	"clinic-go/clinicrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ClinicListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewClinicListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ClinicListLogic {
	return &ClinicListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ClinicListLogic) ClinicList(in *clinicrpc.ClinicListRequest) (*clinicrpc.ClinicListResponse, error) {
	// todo: add your logic here and delete this line

	var clinic mysql.Clinic
	mysql.DB.Debug().Where("id = ?", in.ClinicId).Find(&clinic)

	if in.ClinicId == 0 {
		return nil, errors.New("数据不存在")
	}

	return &clinicrpc.ClinicListResponse{
		Image:    clinic.Image,
		Name:     clinic.Name,
		Phone:    clinic.Phone,
		Address:  clinic.Address,
		Price:    float32(clinic.Price),
		ClinicId: int64(clinic.ID),
	}, nil
}
